
/***************************************************************************
 *   jell - library                                                        *
 *                                                                         *
 *   Copyright (C) 2008 by kuerant                                         *
 *                         <kuerant@gmail.com>                             *
 *                                                                         *
 *   This library is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This library is distributed in the hope that it will be usefull, but  *
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      *
 *   Library General Public License for more details.                      *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this library; if not, write to the Free Software   *
 *   Foundation, Inc., 59 Temple Place - Suite 330, Boston,                *
 *   MA 02111-1307, USA                                                    *
 ***************************************************************************/


#include "jell/netjell.hpp"

#include "jell/jelly.hpp"

namespace   jell
{


///////////////////////////////////////////////////////////////////////
//
// Class NetJell Implementation
//

    ///////////////////////////////////////////////////////////////////

    NetJell::NetJell()
    {
        jelly = new Jelly();
    }

    NetJell::~NetJell()
    {
        if (jelly) {
            delete jelly;
            jelly = NULL;
        }
    }

    NetJell*
    NetJell::create(void)
    {
        NetJell*    jell = new NetJell();

        return  jell;
    }

    ///////////////////////////////////////////////////////////////////

    void
    NetJell::connect(const Address& address) throw (JellException)
    {
        this->jelly->connect(address);
    }

    void
    NetJell::listen(const Address& address) throw (JellException)
    {
        this->jelly->listen(address);
    }

    void
    NetJell::shutdown(const Address& address) throw (JellException)
    {
        this->jelly->shutdown(address);
    }

    void
    NetJell::shutdown() throw (JellException)
    {
        this->jelly->shutdown();
    }

    ///////////////////////////////////////////////////////////////////

    void
    NetJell::run(void)  throw (JellException)
    {
        this->jelly->run();
    }

    ///////////////////////////////////////////////////////////////////

    void
    NetJell::send(const Address& address, Buf& buf, int timeout_in_seconds) throw (JellException)
    {
        this->jelly->send(address, buf, timeout_in_seconds);
    }

    void
    NetJell::recv(Address& address, Buf& buf, int timeout_in_seconds) throw (JellException)
    {
        this->jelly->recv(address, buf, timeout_in_seconds);
    }

    void
    NetJell::sendto(const Address& address, Buf& buf, int timeout_in_seconds) throw (JellException)
    {
        this->jelly->sendto(address, buf, timeout_in_seconds);
    }

    void
    NetJell::recvfrom(Address& address, Buf& buf, int timeout_in_seconds) throw (JellException)
    {
        this->jelly->recvfrom(address, buf, timeout_in_seconds);
    }

    ///////////////////////////////////////////////////////////////////

    Allocator&
    NetJell::allocator() throw (JellException)
    {
        return  *(this->jelly->allocator);
    }

    ///////////////////////////////////////////////////////////////////

    void
    NetJell::addBufHandler(BufHandler& buf_handler) throw (JellException)
    {
        this->jelly->addBufHandler( &buf_handler );
    }

    void
    NetJell::addEventHandler(EventHandler& event_handler) throw (JellException)
    {
        this->jelly->addEventHandler( &event_handler );
    }

    ///////////////////////////////////////////////////////////////////

    void
    NetJell::setLogger(Logger* logger)
    {
        if (logger) {
            this->jelly->logger = logger;
        }
        else {
            this->jelly->logger = jelly->jell_logger;
        }
    }

    Logger*
    NetJell::getLogger(void)
    {
        return  this->jelly->logger;
    }

    ///////////////////////////////////////////////////////////////////

}   // namespace jell
